From 883574d2d4f590eb212cf1321c9982e5ba2ce7c8 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Mon, 23 Jun 2008 18:58:11 +0000 Subject: [PATCH] util: Add bit manipulation functions getbit and setbit. --- gpsbabel/defs.h | 5 +++++ gpsbabel/util.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 40b487eef..701259239 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -930,6 +930,11 @@ typedef enum { #define DATUM_OSGB36 86 #define DATUM_WGS84 118 +/* bit manipulation functions (util.c) */ + +char getbit(const void *buf, const gbuint32 nr); +void setbit(void *buf, const gbuint32 nr); + /* * From parse.c */ diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 41286af81..58600aff2 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -1736,3 +1736,25 @@ char *get_filename(const char *fname) return (res == NULL) ? (char *) fname : ++res; } + +/* bit manipulation functions */ + +/* + * setbit: Set bit number [nr] of buffer [buf] + */ +void setbit(void *buf, const gbuint32 nr) +{ + unsigned char *bytes = buf; + bytes[nr / 8] |= (1 << (nr % 8)); +} + +/* + * setbit: Get state of bit number [nr] of buffer [buf] + */ +char getbit(const void *buf, const gbuint32 nr) +{ + const unsigned char *bytes = buf; + return (bytes[nr / 8] & (1 << (nr % 8))); + +} + -- 2.30.2